﻿Imports CapaLogica.CL.Usuario
Imports CapaLogica.CL.UtilidadesGenerales
Imports System.Configuration

Public Class frmLogin

    ' TODO: Insert code to perform custom authentication using the provided username and password 
    ' (See http://go.microsoft.com/fwlink/?LinkId=35339).  
    ' The custom principal can then be attached to the current thread's principal as follows: 
    '     My.User.CurrentPrincipal = CustomPrincipal
    ' where CustomPrincipal is the IPrincipal implementation used to perform authentication. 
    ' Subsequently, My.User will return identity information encapsulated in the CustomPrincipal object
    ' such as the username, display name, etc.

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        Try
            If validar() Then

                Modulo.setearCadenaDeconexion(My.Settings.conexion)


                If GestorUsuario.iniciarSesion(txtCorreo.Text, txtContrasenna.Text) Then
                    Dim pantalla As frm_inicio = New frm_inicio
                    permisosUsuario(pantalla)
                    Me.Visible = False
                    Common.permisosUsuario(pantalla)
                    pantalla.ShowDialog()
                    txtCorreo.Text = ""
                    txtContrasenna.Text = ""

                    Me.Visible = True

                Else
                    MsgBox("El correo o la contraseña son incorrectos.")
                End If

            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
        End Try



    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Me.Close()
    End Sub

    Private Function validar() As Boolean
        If (txtCorreo.Text = Nothing Or txtContrasenna.Text = Nothing) Then

            MsgBox("Todos los campos son obligatorios ", MsgBoxStyle.Critical)
            Return False

        End If

        Return True
    End Function

    Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class
